<template>
  <div class="receiveSendList">
    <filterPanel filterName="CReceiveSendListFilter" filterTitle="收寄件查询" :filterList="filterData"
                 @filterChange="filterChange"></filterPanel>
    <tablePanel tableName="CReceiveSendListTable" :tableLoading="loading" tableTitle="收寄件列表" :tableList="tableList"
                :tableData="tableData" :total="total" :currentPage="form.page_start" :pageSize="form.page_size"
                @sizeChange="sizeChange" @pageChange="pageChange" @tableClick="tableClick">
      <zy-button type="primary" @click="tableClick('', 'add')">新增</zy-button>
    </tablePanel>
  </div>
</template>

<script>
	export default {
		name: "CReceiveSendList",
		props: {},
		data() {
			return {
				filterData: [
					{
						title: '合作企业',
						name: 'company_name',
						type: 'input',
						value: '',
						maxlength: '20',
						isShow: true,
						isSelected: true
					},
					{
						title: '快递单号',
						name: 'logistics_no',
						type: 'input',
						value: '',
						maxlength: '50',
						isShow: true,
						isSelected: true
					},
					{
						title: '收件人姓名',
						name: 'receive_communicate_name',
						type: 'input',
						value: '',
						maxlength: '20',
						isShow: true,
						isSelected: true
					},
					{
						title: '收件人手机号',
						name: 'receive_communicate_mobile',
						type: 'input',
						value: '',
						maxlength: '11',
						isShow: true,
						isSelected: true
					},
					{
						title: '收件地址',
						name: 'receive_communicate_address',
						type: 'input',
						value: '',
						maxlength: '50',
						isShow: true,
						isSelected: true
					},
					{
						title: '录入时间',
						name: 'time',
						type: 'date',
						value: [],
						isShow: true,
						isSelected: true
					},
					{
						title: '寄件人姓名',
						name: 'post_communicate_name',
						type: 'input',
						value: '',
						maxlength: '20',
						isShow: true,
						isSelected: true
					},
					{
						title: '寄件人手机号',
						name: 'post_communicate_mobile',
						type: 'input',
						value: '',
						maxlength: '11',
						isShow: true,
						isSelected: true
					},
					{
						title: '寄件地址',
						name: 'post_communicate_address',
						type: 'input',
						value: '',
						maxlength: '50',
						isShow: true,
						isSelected: true
					},
					{
						title: '快递类型',
						name: 'logistics_type',
						type: 'select',
						optionList: [
							{label: '全部', value: ''},
							{label: '收件', value: '2'},
							{label: '寄件', value: '1'},
						],
						value: '',
						isShow: true,
						isSelected: true
					},
				],
				form: {
					logistics_type: '',
					company_name: '',
					logistics_no: '',
					post_communicate_name: '',
					post_communicate_mobile: '',
					post_communicate_address: '',
					receive_communicate_name: '',
					receive_communicate_mobile: '',
					receive_communicate_address: '',
					time: [],
					page_start: 1,
					page_size: 10
				},
				loading: false,
				tableList: [
					{
						title: '合作企业',
						width: 200,
						name: 'company_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '快递单号',
						width: 160,
						name: 'logistics_no',
						isShow: true,
						isSelected: true
					},
					{
						title: '快递类型',
						width: 120,
						name: 'logistics_type_desc',
						isShow: true,
						isSelected: true
					},
					{
						title: '收件人姓名',
						width: 120,
						name: 'receive_communicate_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '收件人手机号',
						width: 120,
						name: 'receive_communicate_mobile',
						isShow: true,
						isSelected: true
					},
					{
						title: '收件人地址',
						width: 240,
						name: 'receive_communicate_address',
						isShow: true,
						isSelected: true
					},
					{
						title: '录入时间',
						width: 160,
						name: 'create_time_desc',
						isShow: true,
						isSelected: true
					},
					{
						title: '寄件人姓名',
						width: 120,
						name: 'post_communicate_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '寄件人手机号',
						width: 120,
						name: 'post_communicate_mobile',
						isShow: true,
						isSelected: true
					},
					{
						title: '寄件人地址',
						width: 240,
						name: 'post_communicate_address',
						isShow: true,
						isSelected: true
					},
					{
						title: '操作',
						width: 200,
						name: 'handler',
						fixed: 'right',
						btns: [
							{
								type: 'look',
								name: '详情'
							},
							{
								type: 'edit',
								name: '修改'
							},
						],
						isSelected: true
					}
				],
				tableData: [],
				total: 0,
				download_url: ''
			};
		},
		computed: {
			postData() {
				let data = {
					...this.form,
					pagination: {
						page_start: this.form.page_start,
						page_size: this.form.page_size
					}
				};
				if (this.form.time && this.form.time.length > 0) {
					data.create_time_start = this.form.time[0] / 1000;
					data.create_time_end = this.form.time[1] / 1000;
				}
				return data;
			},
		},
		watch: {
			$route: {
				handler() {
					let {isRefresh} = this.$route.query || {};
					if (isRefresh) this.getData();
				},
				deep: true
			}
		},
		components: {},
		methods: {
			sizeChange(val) {
				this.form.page_size = val;
				this.getData()
			},
			pageChange(val) {
				this.form.page_start = val;
				this.getData()
			},
			filterChange(data) {
				this.form = {...this.form, ...data};
				this.getData();
			},
			getData() {
				this.loading = true;
				this.$axios.post(this.$api.c_listLogistics, this.postData).then(res => {
					let {code, msg, data} = res;
					this.loading = false;
					if (code == 200) {
						this.tableData = data.list.filter(item => {
							item.look = true;
							item.edit = true;
							return item;
						});
						this.total = data.pagination.total_count || 0;
						this.download_url = data.download_url
					} else {
						this.total = 0;
						this.tableData = [];
					}
				}).catch(ret => {
					this.loading = false;
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			},
			tableClick(data, type) {
				this.$toRoutePath({
					path: "/cooperate/receive_send/detail",
					edit: true,
					query: {
						type: type,
						logistics_id: data.logistics_id
					}
				});
			},
			addEquipment() {

			},
			exportUrl() {
				if (this.download_url) {
					window.open(this.download_url, '_blank')
				}
			}
		},
		mounted() {
			this.getData()
		},
		created() {
		}
	}
</script>

<style scoped lang="less" src="@/style/cooperate/receiveSend/receiveSendList/index.less">

</style>
